package com.symaster.common;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * @author yinmiao
 * @date 2021-08-12 09:08
 */
public class IndexMap<T> {

    private final Map<Integer, T> indexMap = new HashMap<>();

    public void put(int index, T value) {
        indexMap.put(index, value);
    }

    public T get(int index) {
        return indexMap.get(index);
    }

    public int size() {
        return indexMap.size();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        IndexMap<?> indexMap1 = (IndexMap<?>) o;
        return Objects.equals(indexMap, indexMap1.indexMap);
    }

    @Override
    public int hashCode() {
        return Objects.hash(indexMap);
    }

    @Override
    public String toString() {
        return "IndexMap{" +
                "indexMap=" + indexMap +
                '}';
    }
}
